using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.DXErrorProvider;
using Common.Class;
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace Common.Base
{
	public class XucBaseXAdd : XucBase
	{
		private IContainer components = null;
		protected GroupControl gcInfo;
		protected LabelControl lblName;
		protected TextEdit txtID;
		protected LabelControl lblId;
		protected ImageCollection imageCollection2;
		protected DXErrorProvider Err;
		protected SimpleButton btnSave;
		protected SimpleButton btnCancel;
		protected SimpleButton btnSaveNew;
		protected ComboBoxEdit txtNAME;
		public event ButtonClickEventHander CancelClick;
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.components = new Container();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(XucBaseXAdd));
			SuperToolTip superToolTip = new SuperToolTip();
			ToolTipItem toolTipItem = new ToolTipItem();
			SuperToolTip superToolTip2 = new SuperToolTip();
			ToolTipItem toolTipItem2 = new ToolTipItem();
			this.gcInfo = new GroupControl();
			this.txtNAME = new ComboBoxEdit();
			this.lblName = new LabelControl();
			this.txtID = new TextEdit();
			this.lblId = new LabelControl();
			this.imageCollection2 = new ImageCollection(this.components);
			this.Err = new DXErrorProvider(this.components);
			this.btnSave = new SimpleButton();
			this.btnCancel = new SimpleButton();
			this.btnSaveNew = new SimpleButton();
			((ISupportInitialize)this.gcInfo).BeginInit();
			this.gcInfo.SuspendLayout();
			((ISupportInitialize)this.txtNAME.Properties).BeginInit();
			((ISupportInitialize)this.txtID.Properties).BeginInit();
			((ISupportInitialize)this.imageCollection2).BeginInit();
			((ISupportInitialize)this.Err).BeginInit();
			base.SuspendLayout();
			this.gcInfo.Controls.Add(this.txtNAME);
			this.gcInfo.Controls.Add(this.lblName);
			this.gcInfo.Controls.Add(this.txtID);
			this.gcInfo.Controls.Add(this.lblId);
			this.gcInfo.Location = new Point(1, 1);
			this.gcInfo.Name = "gcInfo";
			this.gcInfo.Size = new Size(383, 55);
			this.gcInfo.TabIndex = 2;
			this.gcInfo.Text = "Thông tin bắt buộc";
			this.txtNAME.AllowHtmlTextInToolTip = DefaultBoolean.True;
			this.txtNAME.Location = new Point(155, 26);
			this.txtNAME.Name = "txtNAME";
			this.txtNAME.Properties.DropDownRows = 10;
			this.txtNAME.Properties.ImmediatePopup = true;
			this.txtNAME.Properties.PopupSizeable = true;
			this.txtNAME.Size = new Size(222, 20);
			this.txtNAME.TabIndex = 3;
			this.txtNAME.EditValueChanged += new EventHandler(this.TxtNameEditValueChanged);
			this.txtNAME.MouseClick += new MouseEventHandler(this.TxtNameMouseClick);
			this.txtNAME.Leave += new EventHandler(this.TxtNameLeave);
			this.lblName.Location = new Point(126, 30);
			this.lblName.Name = "lblName";
			this.lblName.Size = new Size(18, 13);
			this.lblName.TabIndex = 2;
			this.lblName.Text = "Tên";
			this.txtID.Location = new Point(27, 26);
			this.txtID.Name = "txtID";
			this.txtID.Properties.MaxLength = 20;
			this.txtID.Size = new Size(93, 20);
			this.txtID.TabIndex = 1;
			this.txtID.EditValueChanged += new EventHandler(this.TxtIDEditValueChanged);
			this.txtID.Leave += new EventHandler(this.TxtIDLeave);
			this.txtID.KeyDown += new KeyEventHandler(this.TxtIDKeyDown);
			this.lblId.Location = new Point(6, 29);
			this.lblId.Name = "lblId";
			this.lblId.Size = new Size(14, 13);
			this.lblId.TabIndex = 0;
			this.lblId.Text = "Mã";
			this.imageCollection2.ImageStream = (ImageCollectionStreamer)componentResourceManager.GetObject("imageCollection2.ImageStream");
			this.Err.ContainerControl = this;
			this.btnSave.ImageIndex = 0;
			this.btnSave.ImageList = this.imageCollection2;
			this.btnSave.Location = new Point(89, 78);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new Size(88, 27);
			toolTipItem.Text = "Ctrl+S\r\n";
			superToolTip.Items.Add(toolTipItem);
			this.btnSave.SuperTip = superToolTip;
			this.btnSave.TabIndex = 35;
			this.btnSave.Text = "Lưu && Đóng";
			this.btnSave.Visible = false;
			this.btnSave.Click += new EventHandler(this.BtnSaveClick);
			this.btnSave.KeyDown += new KeyEventHandler(this.BtnSaveKeyDown);
			this.btnCancel.ImageIndex = 6;
			this.btnCancel.ImageList = this.imageCollection2;
			this.btnCancel.Location = new Point(276, 78);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new Size(95, 27);
			this.btnCancel.TabIndex = 36;
			this.btnCancel.Text = "Đóng";
			this.btnCancel.Click += new EventHandler(this.BtnCancelClick);
			this.btnCancel.KeyDown += new KeyEventHandler(this.BtnCancelKeyDown);
			this.btnSaveNew.ImageIndex = 0;
			this.btnSaveNew.ImageList = this.imageCollection2;
			this.btnSaveNew.Location = new Point(183, 78);
			this.btnSaveNew.Name = "btnSaveNew";
			this.btnSaveNew.Size = new Size(87, 27);
			toolTipItem2.Text = "Ctrl+Shift +S";
			superToolTip2.Items.Add(toolTipItem2);
			this.btnSaveNew.SuperTip = superToolTip2;
			this.btnSaveNew.TabIndex = 37;
			this.btnSaveNew.Text = "Lưu";
			this.btnSaveNew.Click += new EventHandler(this.BtnSaveNewClick);
			base.AutoScaleDimensions = new SizeF(6f, 13f);
			base.AutoScaleMode = AutoScaleMode.Font;
			base.Controls.Add(this.btnSaveNew);
			base.Controls.Add(this.btnSave);
			base.Controls.Add(this.btnCancel);
			base.Controls.Add(this.gcInfo);
			this.DoubleBuffered = true;
			base.Name = "XucBaseXAdd";
			base.Size = new Size(386, 108);
			((ISupportInitialize)this.gcInfo).EndInit();
			this.gcInfo.ResumeLayout(false);
			this.gcInfo.PerformLayout();
			((ISupportInitialize)this.txtNAME.Properties).EndInit();
			((ISupportInitialize)this.txtID.Properties).EndInit();
			((ISupportInitialize)this.imageCollection2).EndInit();
			((ISupportInitialize)this.Err).EndInit();
			base.ResumeLayout(false);
		}
		public XucBaseXAdd()
		{
			this.InitializeComponent();
			this.Init();
		}
		public void RaiseCancelClickEventHander()
		{
			if (this.CancelClick != null)
			{
				this.CancelClick(this);
			}
		}
		protected void Init()
		{
			this.ReLoad();
		}
		protected virtual bool Check()
		{
			return true;
		}
		public void Save()
		{
			if (this.txtID.ErrorText != string.Empty | this.txtID.Text == string.Empty)
			{
				XtraMessageBox.Show((this.txtID.ErrorText.Length == 0) ? "Dữ liệu của ô này không được bỏ trống." : this.txtID.ErrorText, "Thông báo");
				this.txtID.Focus();
			}
			else
			{
				if (this.txtNAME.ErrorText != string.Empty | this.txtNAME.Text == string.Empty)
				{
					XtraMessageBox.Show((this.txtNAME.ErrorText.Length == 0) ? "Dữ liệu của ô này không được bỏ trống." : this.txtNAME.ErrorText, "Thông báo");
					this.txtNAME.Focus();
				}
				else
				{
					if (this.Check())
					{
						switch (this.MStatus)
						{
						case Actions.Add:
							this.UcSave();
							break;
						case Actions.Update:
							this.UcUpdate();
							break;
						}
					}
				}
			}
		}
		public virtual void Delete()
		{
			this.UcDelete();
		}
		public virtual void ReLoad()
		{
		}
		protected virtual string UcSave()
		{
			return string.Empty;
		}
		protected virtual string UcUpdate()
		{
			return string.Empty;
		}
		protected virtual string UcDelete()
		{
			return string.Empty;
		}
		private void TxtIDLeave(object sender, EventArgs e)
		{
			TextEdit textEdit = (TextEdit)sender;
			if (this.MStatus != Actions.None)
			{
				if (textEdit.Text == string.Empty)
				{
					this.Err.SetError(textEdit, "Vui lòng nhập thông tin." + this.Text);
					textEdit.Focus();
				}
			}
		}
		protected virtual void TxtIDEditValueChanged(object sender, EventArgs e)
		{
		}
		protected virtual void TxtIDKeyDown(object sender, KeyEventArgs e)
		{
		}
		private void TxtNameLeave(object sender, EventArgs e)
		{
			TextEdit textEdit = (TextEdit)sender;
			if (this.MStatus != Actions.None)
			{
				if (textEdit.Text == string.Empty)
				{
					this.Err.SetError(textEdit, "Vui lòng nhập thông tin." + this.Text);
					textEdit.Focus();
				}
				if (string.IsNullOrEmpty(this.txtID.Text))
				{
					if (!string.IsNullOrEmpty(this.txtNAME.Text))
					{
						this.txtID.Text = base.GenerateCode(this.txtNAME.Text);
					}
				}
			}
		}
		private void TxtNameEditValueChanged(object sender, EventArgs e)
		{
			TextEdit textEdit = (TextEdit)sender;
			if (this.MStatus != Actions.None)
			{
				if (textEdit.ErrorText != string.Empty)
				{
					this.Err.SetError(textEdit, string.Empty);
				}
				this.txtNAME.ClosePopup();
			}
		}
		protected void BtnSaveClick(object sender, EventArgs e)
		{
			this.MCloseOrNew = CloseOrNew.Close;
			this.Save();
		}
		protected void BtnCancelClick(object sender, EventArgs e)
		{
			this.RaiseCancelClickEventHander();
		}
		protected void BtnSaveKeyDown(object sender, KeyEventArgs e)
		{
			this.BtnSaveClick(this.btnSave, e);
		}
		protected void BtnCancelKeyDown(object sender, KeyEventArgs e)
		{
			this.BtnCancelClick(this.btnCancel, e);
		}
		private void BtnSaveNewClick(object sender, EventArgs e)
		{
			this.Save();
			if (this.MStatus == Actions.Add)
			{
				this.txtID.Properties.ReadOnly = false;
				this.Add();
			}
		}
		public virtual void Add()
		{
		}
		protected void SetValue(DataTable data)
		{
			if (data != null)
			{
				if (data.Columns.Count != 0)
				{
					for (int i = 0; i < data.Rows.Count; i++)
					{
						this.txtNAME.Properties.Items.Add(data.Rows[i][0]);
					}
				}
			}
		}
		protected virtual void TxtNameMouseClick(object sender, MouseEventArgs e)
		{
			this.txtNAME.ShowPopup();
		}
	}
}
